<template>
	<view>
		<navbar title="模板中心">
			<view @click="show=true">
				<u-icon name="plus" size="25"></u-icon>
			</view>
		</navbar>
		<view style="padding: 0 10px 10px 10px;">
			<u-subsection :list="list" @change="sub" :current="current"></u-subsection>
		</view>
		<u-divider style="margin: 0;"></u-divider>
		<unicloud-db loadtime="manual" ref="udb" orderby="time desc"
			v-slot:default="{data, loading, error,hasMore, options}" :collection="colList">
			<u-grid v-if="hasMore||data.length>0" border col="2">
				<u-grid-item v-for="item in data">
					<image @click="openImg([item.image],index)" :src="item.image" mode="aspectFit"></image>
					<p style="font-size: 14px;margin: 10px;">{{item.title}}</p>
					<view
						style="height: 40px;display: flex;align-items: center;width: 100%;justify-content: space-between;">
						<view style="display: flex;align-items: center;">
							<u-avatar :src="item.user_id[0].avatar" size="30" style="margin-left: 5px;"></u-avatar>
							<u--text :text="item.user_id[0].nickname" style="margin: 0 5px;" :lines="1"></u--text>
							<u-icon v-if="item.user_id[0].identity=='认证'" name="/static/other/xunzhang.png" size="20" />
						</view>
					</view>
					<u-button v-if="id!=null" @click="select(item.openup)" text="选择" type="primary"
						style="margin: 5px 0 10px 0;width: 150px;"></u-button>
				</u-grid-item>
			</u-grid>
		</unicloud-db>
		<u-modal :show="show" @close="show=false" closeOnClickOverlay title="如何制作模板？"
			content='用户可以使用html设计模板,在自己设备测试成功之后将html文件发给开发者即可,更多内容欢迎咨询客服!' @confirm="goPage('service')"></u-modal>
	</view>
</template>

<script>
	const db = uniCloud.database();
	import ase from '@/common/ar-aes/ar-aes.js'
	export default {
		methods: {
			sub(e) {
				this.current = e
				this.colList = [
					db.collection('template').where(`type=='apk'&&make==${e}`).getTemp(),
					db.collection('uni-id-users').field("nickname,avatar,identity,_id").getTemp()
				]
				this.$nextTick(() => {
					this.$refs.udb.loadData({
						clear: true
					})
				})
			},
			select(openup) {
				db.collection("item").where({
					_id: this.id
				}).update({
					openup: openup
				}).then(res => {
					this.message("选择成功")
					uni.navigateBack();
				})
			}
		},
		onLoad(op) {
			this.colList = [
				db.collection('template').where(`type=='apk'&&make==${this.current}`).getTemp(),
				db.collection('uni-id-users').field("nickname,avatar,identity,_id").getTemp()
			]
			this.$nextTick(() => {
				this.$refs.udb.loadData({
					clear: true
				})
			})
			this.id = op.id
		},
		data() {
			return {
				current: 0,
				list: ["官方制作", "用户自制"],
				id: null,
				show: false,
				colList: [],
				isvip: false
			};
		}
	}
</script>

<style>
	page {
		background-color: white;
	}
</style>